package com.hanma;

import com.hanma.util.DBUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class NewsManager {
    Connection conn = DBUtil.open();
    private PreparedStatement preparedStatement = null;
    private ResultSet resultSet = null;

    public void incrementNewsClickCount(int newsId) {
        String sql = "UPDATE news SET recommend = recommend + 1 WHERE sid = ?";
        try {
            preparedStatement = conn.prepareStatement(sql);
            preparedStatement.setInt(1, newsId);
            preparedStatement.executeUpdate();
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DBUtil.close(resultSet, preparedStatement, conn);
        }
    }

}